package com.ge.mythreed.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ge.mytestparent.dto.Result;
import com.ge.mythreed.dto.req.EncryptReqDto;
import com.ge.mythreed.dto.req.PmPromotionTargetlistReqDto;
import com.ge.mythreed.dto.resp.PmPromotionTargetlistRespDto;
import com.ge.mythreed.service.EncryptDataService;
import com.ge.mythreed.service.PmPromotionTargetlistService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author geqingxiang
 * @PackageName my-project
 * @Package com.ge.mythreed.controller
 * @Date 2024/1/24 14:18
 * @Version 1.0
 */
@Tag(name = "白名单接口", description = "描述")
@RestController
@RequestMapping("pmPromotionTarget")
@Slf4j
public class PmPromotionTargetController {

    @Autowired
    private PmPromotionTargetlistService pmPromotionTargetlistService;
    @Autowired
    private EncryptDataService encryptDataService;

    @Operation(summary = "白名单分页查询")
    @GetMapping("/queryPage")
    public Result<Page<PmPromotionTargetlistRespDto>> queryPage(@ParameterObject PmPromotionTargetlistReqDto pmPromotionTargetlistReqDto) {
        try {
            Page<PmPromotionTargetlistRespDto> pmPromotionTargetlistRespDtoPage = pmPromotionTargetlistService.queryPageList(pmPromotionTargetlistReqDto);
            return Result.success(pmPromotionTargetlistRespDtoPage);
        } catch (Exception e) {
            log.error("失败", e);
            return Result.error();
        }

    }

    @Operation(summary = "加密历史数据")
    @GetMapping("/encryptMobiles")
    public Result<Page<PmPromotionTargetlistRespDto>> encryptMobiles(@ParameterObject EncryptReqDto encryptReqDto) {
        try {
            String result = encryptDataService.encryptMobiles(encryptReqDto);
            return Result.success(result);
        } catch (Exception e) {
            log.error("加密失败", e);
            return Result.error();
        }

    }
}
